package ui.loading
{
	import core.Global;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	
	import interfaces.ILoading;
	
	import module.Atom;
	
	public class McLoading implements ILoading
	{
		private var m_loadManager:LoadingContainer; 	// 父显示对象，loading管理器
		private var m_loading:Atom;					// loading动画素材
		private var m_init:Boolean;					// 加载完成素材		
		
		public function McLoading(mc:LoadingContainer)
		{
			m_loadManager = mc;
			m_loading = Global.loadResource("ui/loading.swf","loading");
			m_loading.addEventListener(Event.CHANGE,onGetLoading);
		}
		
		public function get target():DisplayObject
		{
			return m_loading;
		}
		
		public function showLoading(per:int):void
		{
			trace("loading....",per);
			if(!m_init)return;
			m_loading.visible = true;
			m_loading.obj.gotoAndStop(per);
		}
		
		public function hide():void
		{
			m_loading.visible = false;
		}
		
		private function onGetLoading(e:Event):void
		{
			m_loading.obj.gotoAndStop(1);
			place(m_loading.obj);
			m_loadManager.sendInitMsg();
			m_init = true;
			
		}
		
		private function place(obj:*):void
		{
			obj.x = (Global.stage.stageWidth - m_loading.obj.mcBg.width) / 2;
			obj.y = (Global.stage.stageHeight - m_loading.obj.mcBg.height) / 2
		}
	}
}